package com.liwenfeng.file;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/*
 * 递归删除非空文件夹
 * */
public class DeleteDir {

    public void delDir(File dir) {
        if (dir == null || !dir.exists()) throw new IllegalArgumentException("文件没找到！");
        if (dir.isFile()) {
            System.out.println(dir.getAbsolutePath() + (dir.delete() ? " 删除成功" : " 删除失败"));
            return;
        }
        File[] files = dir.listFiles();
        if (files != null && files.length > 0) {
            for (File file : files) {
                delDir(file);
            }
        }
        System.out.println(dir.getAbsolutePath() + (dir.delete() ? " 删除成功" : " 删除失败"));
    }

    public static void main(String[] args) {
        new DeleteDir().delDir(new File("D:\\java\\out"));
    }
}
